import moment from 'moment';

export function timerFn() {
  const dateList = [];
  let time = moment().startOf('date');
  _.forEach(new Array(96), () => {
    time.add(15, 'minutes');
    const tK = time.format('HHmm') === '0000' ? '2400' : time.format('HHmm');
    dateList.push(tK);
  });
  return dateList;
}

export const option = (data, toolTipFn, capData, brush = true) =>
  Object.assign(
    {
      toolbox: { show: false },
      grid: {
        left: 25,
        right: 5,
        top: 45,
        bottom: 45,
      },
      legend: {
        right: 'center',
        top: 'bottom',
        padding: [16, 0, 0, 0],
        itemGap: 20,
        itemWidth: 15,
        itemHeight: 8,
        textStyle: {
          color: '#D3D4D4',
        },
        show: true,
        data: [
          { name: '固定(MW)', color: '#F67E26' },
          { name: '装机容量(MW)', color: '#27AE60' },
        ].map((v) => ({
          name: v.name,
          itemStyle: {
            opacity: 1,
            borderWidth: 1,
            borderColor: v.color,
            color: '#222629',
          },
        })),
        inactiveColor: '#545454',
        inactiveBorderColor: '#545454',
        inactiveBorderWidth: 'inherit',
      },
      xAxis: {
        type: 'category',
        axisLabel: {
          show: true,
          color: 'rgba(216, 220, 230, 0.4)',
        },
        interval: 12,
        axisTick: {
          show: true,
        },
        axisPointer: {
          label: {
            backgroundColor: '#444444',
            color: 'white',
            shadowBlur: 0,
          },
        },
        data: timerFn(),
        boundaryGap: false,
      },
      yAxis: {
        type: 'value',
        axisLabel: {
          show: true,
          color: 'rgba(216, 220, 230, 0.4)',
        },
        axisLine: {
          show: false,
        },
        axisPointer: {
          label: {
            backgroundColor: '#444444',
            color: 'white',
            shadowBlur: 0,
          },
        },
        splitLine: { lineStyle: { color: '#363636' } },
      },
      tooltip: {
        show: true,
        axisPointer: { type: 'cross' },
        trigger: 'axis',
        formatter: toolTipFn,
      },
      series: [
        {
          data,
          name: '固定(MW)',
          type: 'line',
          step: 'middle',
          lineStyle: { color: '#F67E26' },
          symbol: 'circle',
          symbolSize: 6,
          itemStyle: { color: '#F67E26', borderWidth: 1, borderColor: '#F67E26' },
          z: 2,
        },
        {
          data: capData,
          name: '装机容量(MW)',
          type: 'line',
          step: 'middle',
          lineStyle: { color: '#27AE60' },
          itemStyle: { color: '#27AE60', borderWidth: 1, borderColor: '#27AE60' },
          symbol: 'circle',
          symbolSize: 6,
          z: 3,
        },
      ],
    },
    brush
      ? {
          brush: {
            toolbox: ['lineX'],
            transformable: false,
            xAxisIndex: 'all',
            brushStyle: {
              borderWidth: 0,
              color: 'rgba(73, 75, 78, 0.3)',
            },
            z: 1,
          },
        }
      : {},
  );
